<template>
    <div class="choiceContainer">
        <div>
            <h1>可选单位：</h1>
        </div>
        <div class="radioContainer">
            <el-radio-group v-model="firmId">
                <el-radio  class="choiceRadio" v-for="item in firmList" :key="item.index" :label="item.id+'+'+item.type+'+'+item.organizationCode+'+'+item.socialCreditCode+'+'+item.unitDetailedName+'+'+item.uiteStatus">{{item.unitDetailedName}}</el-radio>
            </el-radio-group>
        </div>
        <div class="choicPagination">
            <el-pagination
            :page-size="10"
            :pager-count="11"
            layout="prev, pager, next"
            :total="total"
            @current-change="pageChange">
            </el-pagination>
        </div>
        <div></div>
        <div class="choiceButton">
            <el-button type="primary" @click="comfirm">确定</el-button>
            <el-button type="success" @click="bindCompany">绑定更多可选单位</el-button>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            firmId:null,
            total:null,
            firmList:[],
            companyId:null,
        }
    },
    mounted:function(){
        //获取选择单位数据
        this.getData();
    },
    methods:{
        // 获取选择单位数据
        getData(){
            let self = this;
            this.$http({
                method:'post',
                url:'/inventory/pageInfo?page=1&&rows=10',
            }).then(function(res){
                console.log(res);
                if(res.data.status === 200){
                    self.firmList = res.data.data.pageDatas;
                    self.total = res.data.data.total;
                }else if(res.data.status === 401){
                    self.$message.error("请先登录！");
                    self.$router.push({ path: "/" });
                }else{
                    self.$message.error(res.data.message);
                }
            }).catch(function(err){
                console.log(err)
            })
            // console.log(this.$route.params.firmList);
            // this.firmList = this.$route.params.firmList;
            // this.total = this.$route.params.total;
        },
        // 点击分页
        pageChange(index){
            let self = this;
            this.$http({
                method:'post',
                url:'/passport/pageInfo?page='+index+'&&rows=1',
            }).then(function(res){
                if(res.status === 200){
                    console.log(res);
                    self.firmList = res.data.pageDatas;
                }else{
                    self.$message.error(data.message);
                }
                console.log(res);
            }).catch(function(err){
                console.log(err);
            })
        },
        // 选择单位
        comfirm(){
            if(this.firmId){
                console.log(this.firmId);
                let label = this.firmId;
                let arr = label.split("+");
                console.log(arr);
                if(arr[1] === 'null'&&arr[5] == 2){
                    this.$router.push({ path: "/choiceFirmType" });
                }else if (arr[1] === 'null'&&arr[5] == 1){
                    this.$router.push({ path: "/choiceFirmType" });
                }else{
                    this.$store.set('type', arr[1]);//存单位类型
                    this.$router.push({ path: "/home"});
                }
                this.companyId = arr[0];
                this.$store.set('companyId', this.companyId);//存单位id
                this.$store.set('organizationCode', arr[2]);//存组织机构代码
                this.$store.set('socialCreditCode', arr[3]);//存统一社会信用代码
                this.$store.set('unitDetailedName', arr[4]);//存单位详细名称
                this.$store.set('uiteStatus', arr[5]);//存单位类型
                console.log(arr);
                console.log(label);
            }else{
                return;
            }
         
        },
        // 绑定单位
        bindCompany(){
            this.$router.push({ path: "/bindCompany" });
        },
    }
}
</script>

